package com.hl.web.fore;

import com.hl.pojo.Question;
import com.hl.pojo.Reply;
import com.hl.service.ReplyService;
import com.hl.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/reply")
public class ReplyController {
    @Autowired
    private ReplyService replyService;
    @GetMapping("/findByUserId")
    public Object findByUserId(Integer userId){
        return ResultEntity.ok(replyService.findByUserId(userId));
    }
    @GetMapping("/findByQuestionId")
    public Object findAll(Integer questionId){
        return ResultEntity.ok(replyService.findByQuestionId(questionId));
    }
    @RequestMapping("/findById")
    public Object findById(Integer id){
        return ResultEntity.ok( replyService.findById(id));
    }
    @RequestMapping("/delete")
    public Object delete(Integer id){
        replyService.delete(id);
        return ResultEntity.ok();
    }
    @PostMapping ("/add")
    public Object add(@RequestBody Reply reply){
        Date date = new Date();
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        reply.setTime(s.format(date));
         replyService.add(reply);
        return ResultEntity.ok();
    }
    @RequestMapping("/update")
    public Object update(Reply reply){
        replyService.update(reply);
        return ResultEntity.ok();
    }
    @GetMapping("/findAll")
    public ResultEntity findAll(){
        return ResultEntity.ok(replyService.findAll());
    }






}
